// pathdialog.cpp
#include "pathdialog.h"
#include "ui_pathdialog.h"
#include <QStringBuilder>

PathDialog::PathDialog(QWidget *parent,
                       const std::vector<Edge*>& path,
                       double totalLength) :
    QDialog(parent),
    ui(new Ui::PathDialog),
    m_path(path),
    m_totalLength(totalLength)
{
    ui->setupUi(this);
    setWindowTitle("路径详情");
    updatePathDisplay();
}

PathDialog::~PathDialog() {
    delete ui;
}

void PathDialog::updatePathDisplay() {
    // 显示总长度
    ui->lengthLabel->setText(QString("总长度: %1 米").arg(m_totalLength, 0, 'f', 2));

    // 构建路径字符串
    QString pathStr;
    if (!m_path.empty()) {
        Vertex* current = m_path.front()->start;
        pathStr = QString::number(current->id);

        for (Edge* edge : m_path) {
            current = (edge->start == current) ? edge->end : edge->start;
            pathStr += " → " % QString::number(current->id);
        }
    }

    ui->pathTextEdit->setPlainText(pathStr);

}

void PathDialog::on_confirmButton_clicked() {
    accept(); // 关闭对话框
}
